package com.atguigu.tingshu.search.mq;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Slf4j
@Component
public class SearchReceiver {

    @Autowired
    private SearchService searchService;
    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void upperAlbum(ConsumerRecord<String, String> record){
        String albumId = record.value();
        if (!StringUtils.isEmpty(albumId)){
            searchService.upperAlbum(Long.parseLong(albumId));
            log.info("上架专辑完毕,album:{}",albumId);
        };
    }
  @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void lowerAlbum(ConsumerRecord<String, String> record){
        String albumId = record.value();
        if (!StringUtils.isEmpty(albumId)){
            searchService.lowerAlbum(Long.parseLong(albumId));
            log.info("下架专辑完毕,album:{}",albumId);
        };
    }

}
